# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=assimp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.4.3
pkgrel=3
pkgdesc="Portable Open Source library to import various well-known 3D model formats in an uniform manner (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.assimp.org/"
msys2_references=(
  "cpe: cpe:/a:assimp:assimp"
)
license=('spdx:BSD-3-Clause')
msys2_repository_url='https://github.com/assimp/assimp'
depends=("${MINGW_PACKAGE_PREFIX}-minizip"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf")
source=(https://github.com/assimp/assimp/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('66dfbaee288f2bc43172440a55d0235dfc7bf885dda6435c038e8000e79582cb')

build() {
  # RelWithDebInfo build type is required to match with qt6-3d (#11959)
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  DXSDK_DIR=${MINGW_PREFIX} \
  cmake \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DASSIMP_WARNINGS_AS_ERRORS=OFF \
    -DASSIMP_BUILD_ASSIMP_TOOLS=ON \
    -DASSIMP_BUILD_ASSIMP_VIEW=$([[ ${CARCH} == aarch64 ]] && echo "OFF" || echo "ON") \
    -DASSIMP_BUILD_TESTS=OFF \
    -DASSIMP_BUILD_ZLIB=OFF \
    -DASSIMP_IGNORE_GIT_HASH=ON \
    -S "${_realname}-${pkgver}" \
    -B "build-${MSYSTEM}"

  cmake --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}"

  install -Dm644 "${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  # Fix cmake files
  local PREFIX_WIN=$(cygpath -am ${MINGW_PREFIX})
  find "${pkgdir}${MINGW_PREFIX}/lib/cmake" -type f -name '*.cmake' \
      -exec sed -i -e "s|${PREFIX_WIN}|\$\{_IMPORT_PREFIX\}|g" {} \;
}
